#!/usr/bin/env python
# encoding: utf-8
"""
@author: youfeng
@email: youfeng243@163.com
@license: Apache Licence
@file: ningbo_2018_count.py
@time: 2018/1/23 09:45
"""

import sys

sys.path.append('..')
sys.path.append('../..')
from common.mongo import MongDb
from logger import Logger

MONGO_CONF = {
    'host': '172.16.215.16',
    'port': 40042,
    'db': 'app_data',
    'username': 'work',
    'password': 'haizhi'
}

# 日志模块
log = Logger('ningbo_2018_count.log').get_logger()

source_db = MongDb(MONGO_CONF['host'], MONGO_CONF['port'], MONGO_CONF['db'],
                   MONGO_CONF['username'],
                   MONGO_CONF['password'], log=log)


def main():
    count = 0
    for item in source_db.traverse_batch_field('zhejiang_ningbo_2017', {'register_date': {'$gte': '2018'}},
                                               ['_id', 'register_code']):
        register_code = item.get('register_code')
        if not isinstance(register_code, basestring):
            continue

        if '3302' in register_code:
            count += 1

    log.info("宁波 2018 count = {}".format(count))


if __name__ == '__main__':
    main()
